// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   CostCaution.java

package include.alarm;

import include.nseer_db.nseer_db;
import java.sql.ResultSet;

public class CostCaution
{

	private ResultSet rs;
	private ResultSet rs1;
	private String sql1;
	private String date;
	private String dbase;
	private String table1;
	private String table2;
	private String table3;
	private String field1;
	private String field2;
	private String field3;
	private String field4;
	private String idgroup[];
	private String alarmgroup[];
	private double tradeTotal;
	private double receipt;
	private double unreceipt;

	public CostCaution()
	{
		rs = null;
		rs1 = null;
		sql1 = "";
		date = "";
		idgroup = new String[0xf4240];
		alarmgroup = new String[0xf4240];
		tradeTotal = 0.0D;
		receipt = 0.0D;
		unreceipt = 0.0D;
	}

	public void cost(String dbase, String table1, String table2, String table3, String field1, String field2, String field3, 
			String field4)
	{
		try
		{
			this.dbase = dbase;
			this.table1 = table1;
			this.table2 = table2;
			this.table3 = table3;
			this.field1 = field1;
			this.field2 = field2;
			this.field3 = field3;
			this.field4 = field4;
			nseer_db db = new nseer_db(dbase);
			String sql3 = (new StringBuilder("delete from ")).append(table1).toString();
			db.executeUpdate(sql3);
			String sql = (new StringBuilder("select * from ")).append(table2).append(" where tag='1'").toString();
			rs = db.executeQuery(sql);
			int i;
			for (i = 0; rs.next(); i++)
			{
				idgroup[i] = rs.getString(field1);
				alarmgroup[i] = rs.getString(field2);
			}

			for (int j = 0; j < i; j++)
			{
				unreceipt = 0.0D;
				sql1 = (new StringBuilder("select * from ")).append(table3).append(" where ").append(field1).append("='").append(idgroup[j]).append("'").toString();
				for (rs1 = db.executeQuery(sql1); rs1.next();)
				{
					tradeTotal += rs1.getDouble(field3);
					receipt += rs1.getDouble(field4);
					unreceipt = tradeTotal - receipt;
				}

				if (unreceipt > Double.parseDouble(alarmgroup[j]))
				{
					double overfund = unreceipt - Double.parseDouble(alarmgroup[j]);
					String sql2 = (new StringBuilder("insert into ")).append(table1).append("(").append(field1).append(",unreceipt,").append(field2).append(",overfund) values('").append(idgroup[j]).append("','").append(unreceipt).append("','").append(alarmgroup[j]).append("','").append(overfund).append("')").toString();
					db.executeUpdate(sql2);
				}
			}

			db.close();
		}
		catch (Exception exception) { }
	}
}
